var home = new Vue({
    el:'#app',
    data () {
        return{
            isShow1: false,
            isShow2: false,
            isShow3: false,
            isShow4: false,
            isShow5: false,
            isShow6: false,
            isShow7: false,
            newsData: [
                {releaseTime:'',
                title:'',
                picture:'',
                id:''
                },
                {releaseTime:'',
                title:'',
                picture:'',
                id:''
                },
                {releaseTime:'',
                title:'',
                picture:'',
                id:''
                },
                {releaseTime:'',
                title:'',
                picture:'',
                id:''
                }
            ],
            news_id:[{id:''}],
            num: 0,
            picArr: ["../picture/home5.png","http://www.lzfxkj.com/templets/1/webSite_20200708//images/3banner.jpg","http://www.lzfxkj.com/templets/1/webSite_20200708//images/1banner.jpg"]
        }
    },
    mounted(){
        // window.onbeforeunload = function(){
        //     document.documentElement.scrollTop = 0;  //ie下
        //     document.body.scrollTop = 0;  //非ie
        // }
        // 计算主要业务是否在可视区
        this.windowScroll ()
        $(window).scroll(this.windowScroll)
        // 轮播图
        setInterval(this.btnRit, 5000);
        // 获取新闻数据
        this.getData()
    },
    methods:{
        btnLeft () {
            if(this.num == 0) {
                this.num = this.picArr.length - 1
            }
            else{
                 this.num--
            }
        },
        btnRit () {
            if(this.num == this.picArr.length - 1) {
                this.num = 0
            }
            else{
                this.num++
            }
        },
        windowScroll () {
            // 窗口高度
            var ks_area = $(window).height()
            // 距离网页顶部距离
            var scrollHeight = $(window).scrollTop()
            // 元素距离顶部的距离
            var img1top = $("#business_logo1").offset().top
            var img2top = $("#business_logo2").offset().top
            var img3top = $("#business_logo3").offset().top
            var img4top = $("#business_logo4").offset().top
            var img5top = $("#business_logo5").offset().top
            var img6top = $("#business_logo6").offset().top
            var newstop = $("#news").offset().top 
            if(ks_area + scrollHeight >= img1top){
                this.isShow1 = true
            }
            if(ks_area + scrollHeight >= img2top){
                this.isShow2 = true
            }
            if(ks_area + scrollHeight >= img3top){
                this.isShow3 = true
            }
            if(ks_area + scrollHeight >= img4top + 100)
            {
                this.isShow4 = true
            }
            if(ks_area + scrollHeight >= img5top + 100){
                this.isShow5 = true
            }
            if(ks_area + scrollHeight >= img6top + 100){
                this.isShow6 = true
            }
            if(ks_area + scrollHeight >= newstop){
                this.isShow7 = true
            }
            },
        destroyed () {
            window.removeEventListener('scroll', this.windowScroll); //销毁滚动事件
        },
        getData(){
            axios.get('http://dl.sword.ink:2334/news').then((res) => {
              this.newsData = res.data.data
              for(var i=0;i < 4; i++ ){
                  this.news_id[i] = './news_detail.html?id=' + this.newsData[i].id
              }
              });
        }
        }
})